let path = require('path')
let webpack = require('webpack')

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'XchatH5Player.js',
    library: 'XchatH5Player', // 指定类库名,主要用于直接引用的方式(比如script)
    libraryExport: "default", // 对外暴露default属性，就可以直接调用default里的属性
		umdNamedDefine: true,
    // globalObject: "typeof self !== 'undefined' ? self : this", // 定义全局变量,兼容node和浏览器运行，避免出现"window is not defined"的情况
    libraryTarget: 'umd' // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
  },
  mode: "production", // 告诉webpack使用production模式的内置优化,
  module: {
    rules: [{
      test: /\.js$/,
      include: [
        path.resolve(__dirname, 'src')
      ],
      exclude: /(node_modules|bower_components)/,
      loader: "babel-loader",
    },{
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name:'/img/[name].[hash:7].[ext]'
        }
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac|swf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name:'/media/[name].[hash:7].[ext]'
        }
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
			{
			  test: /\.scss$/,
			  use: ['style-loader', 'css-loader', 'sass-loader']
			}]
  },
  plugins: [
    new webpack.ProvidePlugin({ // ProvidePlugin 可以将模块作为一个变量，被webpack在其他每个模块中引用。只有你需要使用此变量的时候，这个模块才会被 require 进来。
      _: ['lodash']
    })
  ]
}